<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        const person = {
            name: "Jack",
            age: 18,
            language: ['java', 'js', 'css']
        }
        console.log(Object.keys(person));
        console.log(Object.values(person));
        console.log(Object.entries(person));

        const target = { a: 1 };
        const source1 = { b: 2 };
        const source2 = { c: 3 };
        // {a:1,b:2,c:3}
        Object.assign(target, source1, source2);
        console.log(target);

        // 声明对象简写
        const name = "张三";
        const age = 20;

        const person1 = { name: name, age: age };
        const person2 = { name, age };

        // 对象函数属性简写
        let person3 = {
            name: "Jack",
            eat: function (food) {
                console.log(this.name + "在吃" + food);
            },
            // 箭头函数this不能使用，必须使用对象.属性
            eat2: food => console.log(person.name + "在吃" + food),
            eat3(food) {
                console.log(person.name + "在吃" + food);
            }
        }
        person3.eat("香蕉");
        person3.eat2("苹果");
        person3.eat3("橘子");

        // 对象的扩展运算符
        // 1.拷贝对象（深拷贝）
        let p1 = { name: "Amy", age: 15 };
        let someone = { ...p1 };
        console.log(someone);   // {name: "Amy", age: 15}

        let age1 = { age: 15 };
        let name1 = { name: "Amy" };
        let p2 = { ...age1, ...name1 };
        console.log(p2);


    </script>


</body>

</html>